package br.ufrj.dcc.dm.action;

import java.util.ArrayList;
import java.util.Map;

import br.ufrj.dcc.dm.model.AttributeMetadata;
import br.ufrj.dcc.dm.model.Entry;
import br.ufrj.dcc.dm.model.decisionTree.Tree;
import br.ufrj.dcc.dm.util.ArffDatasetReader;

public class Main {

	private static final String DATASET_PATH = "./resources/br/ufrj/dcc/dm/dataset/original/weather.nominal.arff";
	private static final String ACCURACY_TEST_DATASET_PATH = "./resources/br/ufrj/dcc/dm/dataset/accuracyTest/weather.nominal.test.arff";
	
	private static Map<Integer, AttributeMetadata> attributeMetadataMap;
	
	private static ArffDatasetReader accuracyTestDatasetReader = new ArffDatasetReader(ACCURACY_TEST_DATASET_PATH);
	
	public static void main(String[] args)
	{
		ArrayList<Entry> entries = accuracyTestDatasetReader.assembleEntries();
		
		int badClassifications = 0;
		int total = entries.size();
		
		DecisionTreeBuilder decisionTreeBuilder = new DecisionTreeBuilder(DATASET_PATH);
		decisionTreeBuilder.prePopulate();
		attributeMetadataMap = decisionTreeBuilder.getAttributeMetadataMap();	
		
		decisionTreeBuilder.buildDecisionTree();
		
		System.out.println("____________________________________________________________________");
		System.out.println("____________________________________________________________________");
		System.out.println("_______________________________TREE_________________________________");
		System.out.println("____________________________________________________________________");
		System.out.println("____________________________________________________________________");
		
		decisionTreeBuilder.printDecisionTree(decisionTreeBuilder.getDecisionTree().getRootNode());

		
		
		Tree decisionTree = decisionTreeBuilder.getDecisionTree();
		
		for(Entry entry : entries)
		{
			String decision = decisionTree.decide(entry);
			String expectedDecision = entry.getClassAttribute().getValue();
			
			if(!decision.equalsIgnoreCase(expectedDecision))
			{
				badClassifications ++;
			}
		}
		
		System.out.println("\n\nTree accuracy: " + badClassifications/(double) total);
		
		
	}
	
	
}
